﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
    public class MyDatePickerCtrlViewModel :BaseViewModel<MyDatePickerCtrlViewModel>
    {

        #region Variables


        private string _dateMinute;

        private string _dateSecond;

        private string _dateHour;

        private DateTime _dat;
        #endregion

        #region Constructor

        public MyDatePickerCtrlViewModel()
        {
            _dat = DateTime.Now;
            _dateHour = _dat.Hour.ToString();
            _dateSecond = _dat.Second.ToString();
            _dateMinute = _dat.Minute.ToString();
        }
        public MyDatePickerCtrlViewModel(DateTime _dat)
        {
            this.Dat = _dat;
            _dateHour = _dat.Hour.ToString();
            _dateSecond = _dat.Second.ToString();
            _dateMinute = _dat.Minute.ToString();
        }
        #endregion

        #region Properties


        public string DateHour
        {
            get
            {
                return _dateHour;
            }
            set
            {
                _dateHour = value;
                Update();
                RaisePropertyChanged("DateHour");
            }
        }

        public string DateSecond
        {
            get
            {
                return _dateSecond;
            }

            set
            {
                _dateSecond = value;
                Update();
                RaisePropertyChanged("DateSecond");
            }
        }

        public string DateMinute
        {
            get
            {
                return _dateMinute;
            }
            set
            {
                _dateMinute = value;
                Update();
                RaisePropertyChanged("DateMinute");
            }
        }

        public DateTime Dat
        {
            get
            {
                return _dat;
            }

            set
            {
                _dat = value;
                RaisePropertyChanged("DateHour");
                RaisePropertyChanged("DateSecond");
                RaisePropertyChanged("DateMinute");
            }
        }

        #endregion

        #region Event

        #endregion

        #region Private Methods
        private void Update()
        {
            if (string.IsNullOrEmpty(_dateHour)) _dateHour = "0";
            if (string.IsNullOrEmpty(_dateMinute)) _dateMinute = "0";
            if (string.IsNullOrEmpty(_dateSecond)) _dateSecond = "0";
            int day = _dat.Day;
            int year = _dat.Year;
            int Month = _dat.Month;
            _dat = new DateTime(year, Month, day).AddHours(int.Parse(_dateHour))
                    .AddMinutes(int.Parse(_dateMinute))
                    .AddSeconds(int.Parse(_dateSecond));
        }


        #endregion

        #region Public/Protected Methods
        public void Up_Click(string name)
        {
            int temp;
            switch (name)
            {
                case "_hour":
                    temp = System.Int32.Parse(DateHour);
                    temp++;
                    if (temp > 24)
                    {
                        temp = 0;
                    }
                    DateHour = temp.ToString(); break;

                case "_minute":
                    temp = System.Int32.Parse(DateMinute);
                    temp++;
                    if (temp > 60)
                    {
                        temp = 0;
                    }
                    DateMinute = temp.ToString(); break;

                case "_second":
                    temp = System.Int32.Parse(DateSecond);
                    temp++;
                    if (temp > 60)
                    {
                        temp = 0;
                    }
                    DateSecond = temp.ToString(); break;

                default: Update(); break;
            }
        }
        public void Down_Click(string name)
        {
            int temp;
            switch (name)
            {
                case "_hour":
                    temp = System.Int32.Parse(DateHour);
                    temp--;
                    if (temp < 0)
                    {
                        temp = 23;
                    }
                    DateHour = temp.ToString(); break;

                case "_minute":
                    temp = System.Int32.Parse(DateMinute);
                    temp--;
                    if (temp < 0)
                    {
                        temp = 60;
                    }
                    DateMinute = temp.ToString(); break;

                case "_second":
                    temp = System.Int32.Parse(DateSecond);
                    temp--;
                    if (temp < 0)
                    {
                        temp = 60;
                    }
                    DateSecond = temp.ToString(); break;
                default: Update(); break;
            }
        }

        #endregion

        #region Command

        #region ChangeDoctorCommand

        #endregion

        #region OpenPopupCommand

        #endregion
        #endregion
    }
}
